//package com.echo.echovividlive.schedule;
//
//import cn.hutool.core.util.ArrayUtil;
//import com.echo.echovividlive.service.IUserInteractService;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.data.redis.core.StringRedisTemplate;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Set;
//
//import static com.echo.echovividlive.common.Constants.USER_LIKE_FLAG;
//import static com.echo.echovividlive.common.Constants.USER_LIKE_KEY;
//
//@Slf4j
//@Component
//@RequiredArgsConstructor
//public class AsyncScheduleTask {
//
//    private final IUserInteractService userInteractService;
//    private final StringRedisTemplate stringRedisTemplate;
//    // 每天五分钟自动清理数据库无用字段
//    @Scheduled(cron = "* 0/5 * * * ? ")
//    public void updateUserLikeTable(){
//        Set<String> members = stringRedisTemplate.opsForSet().members(USER_LIKE_FLAG);
//        List<UserLike> userLikes = new ArrayList<>();
//        if (members != null){
//            log.info("进行数据库异步更新...");
//            members.forEach(member -> {
//                Integer userId = Integer.parseInt(member);
//                // 更新每个用户的点赞列表
//                List<String> range = stringRedisTemplate.opsForList().range(USER_LIKE_KEY + userId, 0, -1);
//                String str = ArrayUtil.toString(range);
//                UserLike userLike = new UserLike();
//                userLike.setUserId(userId);
//                userLike.setVideoIds(str);
//                userLikes.add(userLike);
//            });
//            userLikeService.saveBatch(userLikes);
//        }
//    }
//}
